package com.zhiyou.util;

import com.zhiyou.entity.News;

import java.sql.SQLException;
import java.util.ArrayList;

/**
 * @author sanshi
 * @desc
 * @create 2021-09-15 23:24
 */
public class NewsUtil extends DBUtil{
    //根据栏目id得到栏目内新闻
    public ArrayList<News> getNewsByColnID(String cid){
        ArrayList<News> newsList = new ArrayList<News>();
        String sql = "select title,detail from news where chnl_code = ?";
        getConn();
        try {
            ps = connection.prepareStatement(sql);
            ps.setString(1,cid);
            rs = ps.executeQuery();
            while (rs.next()){
                News news = new News(rs.getString("title"), rs.getString("detail"));
                newsList.add(news);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        closeConn();
        return newsList;
    }

}
